#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int max_bridge(vector<pair<int, int>>& v, int pos, int n)
{
        if(n == v.size()){
                return 0;
        }

        if(v[n].second < pos){
                return max_bridge(v, pos, n+1);
        }

        return  max(max_bridge(v, pos, n+1), max_bridge(v, v[n].second, n+1) + 1);
}

int max_up_seq(vector<int> &seq)
{
        int n = seq.size();
        vector<int> dp(n, 1);
        for(int i = 1; i < n; i++){
                for(int j = 0; j < i; j++){
                        if(seq[i] > seq[j]){
                                dp[i] = max(dp[i], dp[j] + 1);
                        }
                }
        }
        return *max_element(dp.begin(), dp.end());
}

int main()
{
        int n;
        cin>>n;
        vector<pair<int, int>> v(n);
        for(int i = 0; i < n; i++){
                cin >> v[i].first >> v[i].second;
        }
        sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b) {
                return a.first < b.first;
        });
        
        vector<int> pos;
        for(int i = 0; i < n; i++){
                pos.push_back(v[i].second);
        }

        //int result = max_bridge(v, v[0].second, 0);
        int result = max_up_seq(pos);
        cout << result << endl;
        return 0;
}